package com.bidding.system.controller;

import com.bidding.common.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户管理控制器
 */
@RestController
@RequestMapping("/system/user")
@Slf4j
@Api(tags = "用户管理", description = "用户管理相关接口")
public class UserController {

    @GetMapping("/hello")
    @ApiOperation(value = "测试接口", notes = "用于测试Knife4j文档是否正常")
    @ApiImplicitParam(name = "name", value = "用户名称", required = true, paramType = "query")
    public Result<String> hello(@RequestParam String name) {
        log.debug("用户名: {}", name);
        return Result.success("你好, " + name);
    }

    @PostMapping("/login")
    @ApiOperation(value = "用户登录", notes = "用户登录接口，验证用户名和密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "form"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "form")
    })
    public Result<Map<String, Object>> login(@RequestParam String username, @RequestParam String password) {
        log.info("用户登录: username={}", username);

        // 模拟登录成功返回数据
        Map<String, Object> data = new HashMap<>();
        data.put("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...");
        data.put("userId", "1001");
        data.put("userName", username);
        data.put("role", "ADMIN");

        return Result.success(data, "登录成功");
    }

    @GetMapping("/info")
    @ApiOperation(value = "获取用户信息", notes = "获取当前登录用户的详细信息")
    public Result<Map<String, Object>> getUserInfo() {
        // 模拟获取用户信息
        Map<String, Object> userInfo = new HashMap<>();
        userInfo.put("userId", "1001");
        userInfo.put("userName", "admin");
        userInfo.put("realName", "系统管理员");
        userInfo.put("email", "admin@example.com");
        userInfo.put("phone", "13800138000");
        userInfo.put("role", "ADMIN");
        userInfo.put("permissions", new String[] {
                "system:user:add",
                "system:user:edit",
                "system:user:delete",
                "system:user:view"
        });

        return Result.success(userInfo);
    }
}
